package com.guida.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.sql.DataSource;

@Configuration
//将MyBatisConfig和JdbcConfig交给Spring管理
//开启事务管理

@Import({MybatisConfig.class, JdbcConfig.class})
@ComponentScan("com.guida.service")
@EnableTransactionManagement // 用于开启Spring事务支持
public class SpringConfig {
    @Bean("transactionManager")
    public DataSourceTransactionManager getDataSourceTxManager(@Autowired DataSource dataSource) {
        DataSourceTransactionManager dtm = new DataSourceTransactionManager();
        dtm.setDataSource(dataSource);
        return dtm;
    }
    /**
     * 上述代码配置了Spring的相关信息，并导入了Mybatis配置类和Spring配置类
     *
     */

}
